<template>
  <div class="chart-container" ref="chartRef"></div>
</template>

<script lang="ts">
export default {
  name: "LineChart",
};
</script>

<script lang="ts" setup>
import * as echarts from "echarts";
import { ref, watch } from "vue";

const chartRef = ref();

const props = defineProps<{
  orderTrend: number[];
  orderTrendAxis: string[];
}>();

watch(
  () => props.orderTrend,
  () => {
    const myEchart = echarts.init(chartRef.value);
    const option = {
      xAxis: {
        data: props.orderTrendAxis,
        //坐标轴留白
        boundaryGap: false,
      },

      grid: {
        left: 0,
        top: 0,
        right: 0,
        bottom: 0,
      },
      yAxis: {
        show: false,
      },
      series: {
        type: "line",
        data: props.orderTrend,
        itemStyle: {
          opacity: "0",
          color: "#a64ca6",
        },
        // 是否平滑曲线显示
        smooth: true,
        areaStyle: {
          color: " #a64ca6",
          opacity: 1,
        },
      },
    };
    myEchart.setOption(option);
  }
);
</script>

<style scoped>
.chart-container {
  height: 100%;
}
</style>
